<?php
// $Id: comment_comment_edit.php,v 1.00 2004/07/09 12:56:00 Yoshi.Sakai Exp $
require('header.php');
include_once XOOPS_ROOT_PATH."/include/xoopscodes.php";
include_once('pop.ini.php');		// Load ini file

	if(!$xoopsUser || !is_object($xoopsUser)){
		redirect_header(XOOPS_URL.'/modules/popnupblog/',2,_MD_POPNUPBLOG_CAN_WRITE_USER_ONLY);
		exit();
	}
	if(!xoops_refcheck()){
		redirect_header(XOOPS_URL.'/modules/popnupblog/',2,'Referer Check Failed');
		exit();
	}
	$commit = isset($HTTP_POST_VARS['commit']) ? 'on' : 'off';
	$preview = isset($HTTP_POST_VARS['preview']) ? 'on' : 'off';
	$delete = isset($HTTP_POST_VARS['delete']) ? 'on' : 'off';
/*	if(!$blog->canWrite()){
		if((!empty($xoopsModuleConfig['POPNUPBLOG_APPL'])) && ($xoopsModuleConfig['POPNUPBLOG_APPL'] == 1) ){
			redirect_header(XOOPS_URL.'/',1,_MD_POPNUPBLOG_NORIGHTTOACCESS.'(1.2)');
			exit();
		}
		$xoopsOption['template_main'] = 'popnupblog_application.html';
	}else{*/
		$param = isset($HTTP_POST_VARS['param']) ? ($HTTP_POST_VARS['param']) : 0;
		$comment_uid = isset($HTTP_POST_VARS['comment_uid']) ? ($HTTP_POST_VARS['comment_uid']) : 0;
		$blogid = isset($HTTP_POST_VARS['blogid']) ? ($HTTP_POST_VARS['blogid']) : 0;
		$vote = isset($HTTP_POST_VARS['vote']) ? $HTTP_POST_VARS['vote'] : 0;
		if($param == 0){
			$param = isset($HTTP_GET_VARS['param']) ? ($HTTP_GET_VARS['param']) : 0;
		}
		if($delete == 'on'){
			if(PopnupBlogUtils::updateComment($comment_uid,$param, null,0)){
				redirect_header(PopnupBlogUtils::createUrl($comment_uid),2,_MD_POPNUPBLOG_DELETE_COMMENT);
				exit();
			}
		} elseif($commit == 'on'){
			$text = isset($HTTP_POST_VARS['text']) ? $HTTP_POST_VARS['text'] : '';
echo ":".$comment_uid.":".$param.":". $text. ":".$vote;
			if(PopnupBlogUtils::updateComment($comment_uid,$param, $text, $vote)){
				redirect_header(PopnupBlogUtils::createUrl($blogid),2,_MD_POPNUPBLOG_THANKS_COMMENT);
				exit();
			}
		}else{
			if($preview == 'on'){
				$ts =& MyTextSanitizer::getInstance();
				$formValue['text'] = $HTTP_POST_VARS['text'];
				$formValue['text'] = $ts->previewTarea($formValue['text'], 0, 1, 1, 1, 1);
				$formValue['text_edit'] = $HTTP_POST_VARS['text'];
				$formValue['text_edit'] = $ts->makeTboxData4PreviewInForm($formValue['text_edit']);
				echo "<p><table class='outer' cellspacing='1'>\n";
				echo "<tr><th>"._MD_POPNUPBLOG_FORM_PREVIEW."</th></tr>\n";
				echo '<tr class="even"><td><div class="comText">'.$formValue['text'].'</div></td></tr>';
				echo "</table></p>\n";
			}else{
				$result = PopnupBlogUtils::getComment1($param);
				$comment_uid = $result['comment_uid'];
				$formValue['blogid']  = array_key_exists('blogid', $result)  ? $result['blogid']  : "";
				$formValue['comment_uid']  = array_key_exists('comment_uid', $result)  ? $result['comment_uid']  : "";
				$formValue['text']  = array_key_exists('text', $result)  ? $result['text']  : "";
				$formValue['text_edit']  = array_key_exists('text_edit', $result)  ? $result['text_edit']  : "";
				$formValue['vote']  = array_key_exists('vote', $result)  ? $result['vote']  : "";
			}
			$GLOBALS['text'] = $formValue['text_edit'];
			echo "<!-- begin of popnupblog edit form -->\n";
			echo "<table class='outer' cellspacing='1'>\n";
			echo '<form method="post" action="'.XOOPS_URL.'/modules/popnupblog/comment_edit.php">'."\n";
			echo '<tr><td align="left" class="head">'._MD_POPNUPBLOG_FORM_COMMENT."</td>\n";
			echo '<td class="even" >';
			echo '<input type="text" name="text" value="'.$GLOBALS['text'].'" size="80" />';
			echo _MD_POPNUPBLOG_FORM_VOTE.":";
			switch ($result['vote']){
				case 0: 
					$ychk= ""; $ymsg=_MD_POPNUPBLOG_FORM_YES;
					$nchk= ""; $nmsg=_MD_POPNUPBLOG_FORM_NO;
					$yval=1; $nval=-1;
					break;
				case 1: 
					$ychk= " CHECKED"; $ymsg=_MD_POPNUPBLOG_FORM_YES;
					$nchk= ""; $nmsg=_MD_POPNUPBLOG_FORM_CANCEL;
					$yval=1; $nval=0;
					break;
				case -1: 
					$ychk= ""; $ymsg=_MD_POPNUPBLOG_FORM_CANCEL;
					$nchk= " CHECKED"; $nmsg=_MD_POPNUPBLOG_FORM_NO;
					$yval=0; $nval=-1;
					break;
			}
			echo '<input type="radio" name="vote" value='.$yval.' '.$ychk.'>'.$ymsg.'</input>';
			echo '<input type="radio" name="vote" value='.$nval.' '.$nchk.'>'.$nmsg.'</input>';
			echo '<input type="hidden" name="param" value='.$param.' />'."\n";
			echo '<input type="hidden" name="comment_uid" value='.$comment_uid.' />'."\n";
			echo '<input type="hidden" name="blogid" value='.$result['blogid'].' />'."\n";
//			echo '<input type="hidden" name="date" value='.$date.' />'."\n";
//			echo '<input type="hidden" name="name" value='.$name.' />'."\n";
			echo '</td></tr><tr><td align="center" colspan="2" class="odd">
				<input type="submit" value="'._MD_POPNUPBLOG_FORM_DELETE.'" name="delete"/> &nbsp 
				<input type="submit" value="'._MD_POPNUPBLOG_FORM_PREVIEW.'" name="preview"/> &nbsp 
				<input type="submit" value="'._MD_POPNUPBLOG_FORM_SEND.'" name="commit"/>';
			echo "\n";
			echo "<!-- begin of popnupblog edit form -->\n";
			echo "</td></tr></form>\n";
			echo "</table>\n";
		}
	//}
require('footer.php');
// Support for Multi-byte filename.
//   By yoshis  2004/4/11
function cnv_mbstr($str) {
	if (extension_loaded('mbstring')){
		return  mb_convert_encoding($str,$BlogCNF['save_as_mbstr'],"auto");
	} else {
		return $str;
	}
}
?>